/**
 * Created by Administrator on 2017/5/12.
 */

window.onload = function(){
    var n=0;
    var imgHeader = document.getElementsByClassName('photoHeader');
    for(n;n<imgHeader.length;n++){
    var img= imgHeader[n];
    var widthC=imgHeader[n].parentNode.offsetWidth;
    var heightC =imgHeader[n].parentNode.offsetHeight;
    Pic(img,widthC,heightC);
    }
    function Pic(obj,width, height)
    { var img=new Image();
    img.src=obj.src;
    var scale=Math.max(width/img.width, height/img.height);
    var newWidth=img.width*scale;
    var newHeight=img.height*scale;
    var div=obj.parentNode;
    obj.width=newWidth;
    obj.height=newHeight;
    div.style.width=width+"px";
    div.style.height=height+"px";
    div.style.overflow="hidden";
    obj.style.marginLeft=(width-newWidth)/2+"px";
    obj.style.marginTop=(height-newHeight)/2+"px";
    }

    }
